const app = getApp()

Page({

    /**
     * 页面的初始数据
     */
  data: {
    hotCity: [
      {
        name: '佛山',
        cityCode: '440600',
        provinceCode: '440100',
        province: '广东省'
      },{
        name: '徐州',
        cityCode: '320300',
        provinceCode: '320000',
        province: '江苏省'
      }
      ,{
        name: '邯郸',
        cityCode: '130400',
        provinceCode: '130000',
        province: '河北省'
      },{
        name: '株洲',
        cityCode: '430200',
        provinceCode: '430000',
        province: '湖南省'
      },{
        name: '沈阳',
        cityCode: '210100',
        provinceCode: '210000',
        province: '辽宁省'
      },{
        name: '贵阳',
        cityCode: '520100',
        provinceCode: '520000',
        province: '贵州省'
      }, {
        name: '宁波',
        cityCode: '330200',
        provinceCode: '330000',
        province: '浙江省'
      }, {
        name: '长沙',
        cityCode: '430100',
        provinceCode: '430000',
        province: '湖南省'
      }],
    southCity: [{
      name: '上海',
      cityCode: '310100',
      provinceCode: '310000',
      province: '上海'
    },{
      name: '成都',
      cityCode: '510100',
      provinceCode: '510000',
      province: '四川省'
    }, {
      name: '重庆',
      cityCode: '500100',
      provinceCode: '500000',
      province: '重庆'
    }, {
      name: '长沙',
      cityCode: '430100',
      provinceCode: '430000',
      province: '湖南省'
    },{
      name: '武汉',
      cityCode: '420100',
      provinceCode: '420000',
      province: '河北省'
    },
    {
      name: '岳阳',
      cityCode: '430600',
      provinceCode: '430000',
      province: '湖南省'
    },
    {
      name: '衡阳',
      cityCode: '430400',
      provinceCode: '430000',
      province: '湖南省'
    },
    {
      name: '株洲',
      cityCode: '430200',
      provinceCode: '430000',
      province: '湖南省'
    },{
      name: '郴州',
      cityCode: '431000',
      provinceCode: '430000',
      province: '湖南省'
    },{
      name: '常德',
      cityCode: '430700',
      provinceCode: '430000',
      province: '湖南省'
    },{
      name: '湘潭',
      cityCode: '430300',
      provinceCode: '430000',
      province: '湖南省'
    },
    {
      name: '合肥',
      cityCode: '340100',
      provinceCode: '340000',
      province: '安徽省'
    },{
      name: '阜阳',
      cityCode: '341200',
      provinceCode: '340000',
      province: '安徽省'
    },{
      name: '南昌',
      cityCode: '360100',
      provinceCode: '360000',
      province: '江西省'
    },{
      name: '九江',
      cityCode: '360400',
      provinceCode: '360000',
      province: '江西省'
    },{
      name: '赣州',
      cityCode: '360700',
      provinceCode: '360000',
      province: '江西省'

    },{
      name: '上饶',
      cityCode: '361100',
      provinceCode: '360000',
      province: '江西省'
    },{
      name: '泉州',
      cityCode: '350500',
      provinceCode: '350000',
      province: '福建省'
    },{
      name: '贵阳',
      cityCode: '520100',
      provinceCode: '520000',
      province: '贵州省'
    },{
      name: '昆明',
      cityCode: '530100',
      provinceCode: '530000',
      province: '云南省'
    },{
      name: '遵义',
      cityCode: '520300',
      provinceCode: '520000',
      province: '贵州省'
    },  {
      name: '南宁',
      cityCode: '450100',
      provinceCode: '450000',
      province: '广西省'
    }, {
      name: '梧州',
      cityCode: '450400',
      provinceCode: '450000',
      province: '广西省'
    },
    {
      name: '眉山',
      cityCode: '511400',
      provinceCode: '510000',
      province: '四川省'
    },
    {
      name: '乐山',
      cityCode: '511100',
      provinceCode: '510000',
      province: '四川省'
    }
    ],
    northCity: [
      {
        name: '天津',
        cityCode: '120100',
        provinceCode: '120000',
        province: '天津'
      }, {
        name: '沈阳',
        cityCode: '210100',
        provinceCode: '210000',
        province: '辽宁省'
      },
      {
        name: '郑州',
        cityCode: '410100',
        provinceCode: '410100',
        province: '河南省'
      },
      {
        name: '邯郸',
        cityCode: '130400',
        provinceCode: '130000',
        province: '河北省'
      },{
        name: '开封',
        cityCode: '410200',
        provinceCode: '410000',
        province: '河南省'
      },{
        name: '石家庄',
        cityCode: '130100',
        provinceCode: '130000',
        province: '河北省'
      }, {
        name: '邢台',
        cityCode: '130500',
        provinceCode: '130000',
        province: '河北省'
      },  {
        name: '盘锦',
        cityCode: '211100',
        provinceCode: '210000',
        province: '辽宁省'
      }
    ],
    guangdongCity: [
      {
        name: '广州',
        cityCode: '440100',
        provinceCode: '440000',
        province: '广东省'
      },
      {
        name: '佛山',
        cityCode: '440600',
        provinceCode: '440000',
        province: '广东省'
      },{
        name: '肇庆',
        cityCode: '441200',
        provinceCode: '440000',
        province: '广东省'
      },
      {
        name: '江门',
        cityCode: '440700',
        provinceCode: '440000',
        province: '广东省'
      },
      {
        name: '中山',
        cityCode: '442000',
        provinceCode: '440000',
        province: '广东省'
      },{
        name: '阳江',
        cityCode: '441700',
        provinceCode: '440000',
        province: '广东省'
      },
      {
        name: '河源',
        cityCode: '441600',
        provinceCode: '440000',
        province: '广东省'
      },
      {
        name: '惠州',
        cityCode: '441300',
        provinceCode: '440000',
        province: '广东省'
      },
      {
        name: '茂名',
        cityCode: '440900',
        provinceCode: '440000',
        province: '广东省'
      }
    ],
    jiangzheCity: [
      {
        name: '宁波',
        cityCode: '330200',
        provinceCode: '330000',
        province: '浙江省'
      },{
        name: '舟山',
        cityCode: '330900',
        provinceCode: '330000',
        province: '浙江省'
      }, {
        name: '台州',
        cityCode: '331000',
        provinceCode: '330000',
        province: '浙江省'
      },{
        name: '金华',
        cityCode: '330700',
        provinceCode: '330000',
        province: '浙江省'
      },{
        name: '南京',
        cityCode: '320100',
        provinceCode: '320000',
        province: '江苏省'
      },{
        name: '苏州',
        cityCode: '320500',
        provinceCode: '320000',
        province: '江苏省'
      },{
        name: '无锡',
        cityCode: '320200',
        provinceCode: '320000',
        province: '江苏省'
      },{
        name: '常州',
        cityCode: '320400',
        provinceCode: '320000',
        province: '江苏省'
      },{
        name: '镇江',
        cityCode: '321100',
        provinceCode: '320000',
        province: '江苏省'
      },{
        name: '扬州',
        cityCode: '321000',
        provinceCode: '320000',
        province: '江苏省'
      },
      {
        name: '徐州',
        cityCode: '320300',
        provinceCode: '320000',
        province: '江苏省'
      },
      {
        name: '南通',
        cityCode: '320600',
        provinceCode: '320000',
        province: '江苏省'
      },
      {
        name: '泰州',
        cityCode: '321200',
        provinceCode: '320000',
        province: '江苏省'
      }
      
    ],

    locationCity: '获取中...',
    allCity: {
      name: '全国',
      cityCode: null
    }
  },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        const that = this;
        if (app.globalData.cityData && JSON.stringify(app.globalData.cityData) !== "{}") {
            this.setData({
                locationCity: app.globalData.cityData.city
            })
        } else {
            this.setData({
                locationCity: '获取中...'
            })
        }
    },
    selectCity(e) {
        console.log(e.target.dataset.code);
        const {
            name,
            cityCode,
            province,
            provinceCode
        } = e.target.dataset.code;
        
        app.globalData.cityData = {
            city: name,
            cityadcode: cityCode,
            province,
            provinceCode
        };
        wx.navigateBack({
            delta: 1,
            success: function (e) {
                console.log(getCurrentPages().pop())
                var page = getCurrentPages().pop();
                if (page == undefined || page == null) return;
                page.onLoad();
            }
        })
        app.globalData.searchKey = '';
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
 
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})